<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>变量与数组模式绑定</title>
        <style>
            .demo {
                width: 100px;
                height: 100px;
                background-color: gray;
                display: inline-block;
                margin: 10px;
            }

            .red {
                background-color: red;
            }

            .green {
                background-color: green;
            }

            .blue {
                background-color: blue;
            }
        </style>
        <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.12/vue.js"></script>
    </head>

    <body>
        <div id="app">
            <div class="demo"></div>
            <div class="demo" :class="{red:attachRed}"></div>
            <div
                class="demo"
                @click="attachRed = !attachRed"
                :class="divClasses"
            ></div>
            <!-- TODO:通过改变input的值可以设置div的样式，改变值的范围是red/green/blue-->
            <!-- TODO:尝试设置数组形式，这样就是多样式操作 -->
        </div>
        <script type="text/javascript">
            new Vue({
                el: '#app',
                data: {
                    attachRed: false,
                },
                computed: {
                    divClasses: function () {
                        return {
                            red: this.attachRed,
                            blue: !this.attachRed,
                        };
                    },
                },
            });
        </script>
    </body>
</html>
